﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Web.Services;
using Newtonsoft.Json;
using RN.ERP.Web.ModelService;

namespace RN.ERP.Web.Exam
{
    public partial class BmQCList : BasePage
    {
        #region Params

        private string pageCode = "QC";
        
        private string page = "BmQCList.aspx";
        
        private string AppID
        {
            get
            {
                return HttpContext.Current.Application[ApplicationConstant.APPLICATION_ID].ToString();
            }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

            }
        }

        protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            RadGrid1.AllowCustomPaging = true;
            int pageCount = RadGrid1.CurrentPageIndex;
            int pageSize = RadGrid1.PageSize;
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                int count = 0;
                var exam = JsonConvert.DeserializeObject<List<ModelService.Exam_QC>>(client.GetExamQCList
                    (pageCode, UserInfo.RoleId, page, AppID, pageCount + 1, pageSize, out count));
                RadGrid1.VirtualItemCount = count;
                RadGrid1.DataSource = exam;
            }
        }

        /// <summary>
        /// 根据【纳入考试人员】的value，返回显示的内容
        /// </summary>
        public string GetExamineeTypeText(object eType)
        {
            string result = String.Empty;
            string eTypeStr;

            if (eType != null && !String.IsNullOrEmpty(eTypeStr = eType.ToString()))
            {
                if (eTypeStr.Contains(",1,"))
                {
                    result += ",初始申请人员";
                }
                if (eTypeStr.Contains(",2,"))
                {
                    result += ",资格复审人员";
                }
                result = result.Substring(1);
            }
            return result;
        }

        [WebMethod]
        public static string DelQC(object id)
        {
            string ret = null;
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                OperationResult result = new OperationResult();
                result = JsonConvert.DeserializeObject<ModelService.OperationResult>(client.DeleteExamQC(int.Parse(id.ToString())));
                ret = JsonConvert.SerializeObject(new { Message = result.Message });
            }
            return ret;
        }
    }
}